<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{this.$store.state.num}}</h1>
        <button @click="add">加一</button>
    </div>
</body>
<script src="./node_modules/vue/dist/vue.js"></script>
<script src="./node_modules/vuex/dist/vuex.js"></script>
<script>
    //Vuex独享
    //a,1 Vuex.Store 对象
    let store = new Vuex.Store({
        //state 仓库数据
        state:{
            num:999
        },
        mutations:{
            //加的操作
            jia:function(state){
                state.num++; //999+1
                console.log(state)
            }
        }
    })
    //a.2 作为配置 传到Vue实例中
    //this.$store 访问到仓库
    let vm = new Vue({
        el:"#app",
        store:store,
        methods:{
            add:function(){
                //
                this.$store.commit("jia");
            }
        }
    })
</script>
</html>